package com.ruoyi.manager.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manager.domain.SoldierSpecialCare;
import com.ruoyi.manager.service.ISoldierSpecialCareService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 优抚对象Controller
 *
 * @author Allen
 * @date 2021-08-31
 */
@RestController
@RequestMapping("/manager/care")
public class SoldierSpecialCareController extends BaseController {
    @Autowired
    private ISoldierSpecialCareService soldierSpecialCareService;

    /**
     * 查询优抚对象列表
     */
    @PreAuthorize("@ss.hasPermi('manager:care:list')")
    @GetMapping("/list")
    public TableDataInfo list(SoldierSpecialCare soldierSpecialCare) {
        startPage();
        List<SoldierSpecialCare> list = soldierSpecialCareService.selectSoldierSpecialCareList(soldierSpecialCare);
        return getDataTable(list);
    }

    /**
     * 导出优抚对象列表
     */
    @PreAuthorize("@ss.hasPermi('manager:care:export')")
    @Log(title = "优抚对象", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SoldierSpecialCare soldierSpecialCare) {
        List<SoldierSpecialCare> list = soldierSpecialCareService.selectSoldierSpecialCareList(soldierSpecialCare);
        ExcelUtil<SoldierSpecialCare> util = new ExcelUtil<SoldierSpecialCare>(SoldierSpecialCare.class);
        return util.exportExcel(list, "优抚对象数据");
    }

    /**
     * 获取优抚对象详细信息
     */
    @PreAuthorize("@ss.hasPermi('manager:care:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(soldierSpecialCareService.selectSoldierSpecialCareById(id));
    }

    /**
     * 新增优抚对象
     */
    @PreAuthorize("@ss.hasPermi('manager:care:add')")
    @Log(title = "优抚对象", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SoldierSpecialCare soldierSpecialCare) {
        return toAjax(soldierSpecialCareService.insertSoldierSpecialCare(soldierSpecialCare));
    }

    /**
     * 修改优抚对象
     */
    @PreAuthorize("@ss.hasPermi('manager:care:edit')")
    @Log(title = "优抚对象", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SoldierSpecialCare soldierSpecialCare) {
        return toAjax(soldierSpecialCareService.updateSoldierSpecialCare(soldierSpecialCare));
    }

    /**
     * 删除优抚对象
     */
    @PreAuthorize("@ss.hasPermi('manager:care:remove')")
    @Log(title = "优抚对象", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(soldierSpecialCareService.deleteSoldierSpecialCareByIds(ids));
    }

    @PutMapping("/audit")
    @Log(title = "优抚对象", businessType = BusinessType.UPDATE)
    public AjaxResult audit(@RequestParam("id") Long id, @RequestParam("auditStatus") Integer auditStatus) {
        return toAjax(soldierSpecialCareService.audit(id,auditStatus));
    }
}
